package br.usp.ime.ingpos.testes.services;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import org.junit.Before;
import org.junit.Test;

import br.com.caelum.vraptor.interceptor.multipart.DefaultUploadedFile;
import br.com.caelum.vraptor.interceptor.multipart.UploadedFile;
import br.usp.ime.ingpos.services.UploadService;
import br.usp.ime.ingpos.testes.IngPosTestCase;

public class UploadServiceTeste
    extends
        IngPosTestCase
{

    private UploadService uploadService;

    public UploadServiceTeste(
        String name )
    {
        super( name );
    }

    @Before
    protected void setUp()
        throws Exception
    {
        super.setUp();
        this.uploadService = new UploadService();
    }

    @Test
    public void testgetNomeDoArquivoSemExtesao()
    {
        final String nomeArquivo = "arquivo";
        final String tipoArquivo = "pdf";
        final String nomeArquivoCompleto = nomeArquivo + "." + tipoArquivo;
        UploadedFile uploadedFile;
        try {
            uploadedFile = new DefaultUploadedFile( new FileInputStream( new File(
                nomeArquivoCompleto ) ), nomeArquivoCompleto, tipoArquivo );

            assertEquals( nomeArquivo, uploadService.getNomeDoArquivoSemExtensao( uploadedFile ) );
        } catch( FileNotFoundException e ) {
            e.printStackTrace();
            assertTrue( false );
        }
    }
    
    @Test
    public void testUpload() {
    	assertEquals (this.uploadService.getSizeLimit(), 15 * 1024 * 1024);
    }
}
